<template>
    <div class="article-lists">
        <el-card class="!border-none" shadow="never">
            <el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true">
                <el-form-item label="订单编号">
                    <el-input
                        class="w-[280px]"
                        v-model="queryParams.orderSn"
                        clearable
                        @keyup.enter="resetPage"
                    />
                </el-form-item>
              <el-form-item label="手机号">
                <el-input
                    class="w-[280px]"
                    v-model="queryParams.mobile"
                    clearable
                    @keyup.enter="resetPage"
                />
              </el-form-item>
              <el-form-item label="订单类型">
                <el-select class="!w-[280px]" v-model="queryParams.type">
                  <el-option label="全部" value />
                  <el-option
                      label="现金订单"
                      :value="1"
                  />
                  <el-option
                      label="积分订单"
                      :value="2"
                  />
                </el-select>
              </el-form-item>
                <el-form-item label="订单状态">
                    <el-select class="!w-[280px]" v-model="queryParams.status">
                        <el-option label="全部" value />
                        <el-option
                            v-for="item in statusOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </el-form-item>
                <el-form-item label="订单时间">
                    <daterange-picker
                        v-model:startTime="queryParams.beginTime"
                        v-model:endTime="queryParams.endTime"
                    />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none mt-4" shadow="never">
            <el-table size="large" v-loading="pager.loading" :data="pager.lists">
                <el-table-column label="订单编号" prop="orderSn" min-width="80" />
                <el-table-column label="收货信息" min-width="100">
                    <template #default="{ row }">
                        <span>{{ getWholeAddress(row) }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="订单状态" prop="type" min-width="100">
                    <template #default="{ row }">
                        <span>{{ statusMap[row.status] }}</span>
                    </template>
                </el-table-column>
              <el-table-column label="订单金额" prop="payAmount" min-width="80" />
              <el-table-column label="供货链结算价¥" prop="supplierChainAmount" min-width="100">
              </el-table-column>
              <el-table-column label="平台结算价¥" prop="platformAmount" min-width="100">
              </el-table-column>
              <el-table-column label="分店结算价¥" min-width="80" prop="shopAmount">
              </el-table-column>
                <el-table-column label="创建时间" min-width="80" prop="createTime">
                </el-table-column>
                <el-table-column label="操作" width="120" fixed="right">
                    <template #default="{ row }">
                        <el-button type="primary" link>
                            <router-link
                                :to="{
                                    path: `/transaction/detail?id=${row.id}`,
                                    query: {
                                        id: row.id
                                    }
                                }"
                            >
                                查看详情
                            </router-link>
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
    </div>
</template>
<script lang="ts" setup name="articleLists">
import { usePaging } from '@/hooks/usePaging'
import { listPage } from '@/servers/order/api/supplyChaindingdanguanli'

const statusMap: any = {
    1: '待付款',
    2: '待发货',
    3: '已发货',
    4: '已完成',
    5: '已取消',
    6: '已退款',
    7: '待退款'
}

const statusOptions = Object.keys(statusMap).map((i: any, index: number) => ({
    label: statusMap[index + 1],
    value: index + 1
}))

function getWholeAddress(row: any) {
    const { receiverProvince, receiverCity, receiveRegion, receiveAddress } = row
    return [receiverProvince, receiverCity, receiveRegion, receiveAddress].filter(Boolean).join('')
}

const queryParams = reactive({
    orderSn: undefined,
    status: undefined,
    type: undefined,
    beginTime: undefined,
    endTime: undefined
})

const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: listPage,
    params: queryParams
})

onActivated(() => {
    // getLists()
})

getLists()
</script>
